﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla.Validation;
using Csla;

namespace Kiosk.Library
{
    public partial class Notification
    {

        protected override void AddBusinessRules()
        { 
            ValidationRules.AddRule(CommonRules.StringRequired, TitleProperty );
            ValidationRules.AddRule(CommonRules.StringRequired, DescriptionProperty);
            ValidationRules.AddRule<Notification>(DateInFuture<Notification>, NotificationDateProperty);
            
        }
        private static bool DateInFuture<T>(T target, Csla.Validation.RuleArgs e) where T : Notification
        {
            if (target.GetProperty<DateTime?>(NotificationDateProperty).GetValueOrDefault() <= DateTime.Now)
            {
                e.Description = "Notification date must be in the future";
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
